//
//  JCVerificationCell.swift
//  JChat
//
//  Created by JIGUANG on 2017/4/6.
//  Copyright © 2017年 HXHG. All rights reserved.
//

import UIKit
import JMessage
import MTCategory

class JCContacterFriendCell: UITableViewCell {

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = UIColor.theme.background
        backgroundColor = UIColor.theme.background
        selectionStyle = .none
        setupUI()
        makeConstraint()
    }
    
    open class func reuseIdentity() -> String {
        return "JCContacterFriendCellID"
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupUI()
        makeConstraint()
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setupUI()
        makeConstraint()
    }
    
    public func bindDate(_ user : JMSGUser) {
        self.nameLabel.text = user.displayName()
//        user.thumbAvatarData({ (data, name, error) in
//            if let data = data {
//                let image = UIImage(data: data)
//                self.avatorImgV.image = image
//            } else {
//                self.avatorImgV.image = UIImage.loadImage("com_icon_user_36")
//            }
//        })
        self.avatorImgV.mtSetImage(user.avatar, nil)
    }
    
    private var info: JCVerificationInfo!
    
    func setupUI() {
        contentView.addSubview(avatorImgV)
        contentView.addSubview(nameLabel)
//        contentView.addSubview(descLabel)
//        contentView.addSubview(lineView)
//        contentView.addSubview(accessImgView)
    }
    
    func makeConstraint() {
        avatorImgV.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(44)
        }
        
        nameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(avatorImgV.snp.right).offset(11)
            //make.bottom.equalTo(contentView.snp.centerY).offset(-2)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-11)
        }
        
//        descLabel.snp.makeConstraints { (make) in
//            make.left.equalTo(nameLabel)
//            make.top.equalTo(contentView.snp.centerY).offset(2)
//        }
        
//        lineView.snp.makeConstraints { (make) in
//            make.right.equalToSuperview().offset(20)
//            make.left.bottom.equalToSuperview()
//            make.height.equalTo(0.5)
//        }
        
//        accessImgView.snp.makeConstraints { (make) in
//            make.centerY.equalToSuperview()
//            make.right.equalToSuperview().offset(-15)
//        }
    }
    
    lazy var accessImgView: UIImageView = {
        let imgV: UIImageView = UIImageView()
        imgV.image = UIImage(named: "icon_chat")
        imgV.sizeToFit()
        return imgV
    }()
    
    lazy var avatorImgV: UIImageView = {
        let imgV: UIImageView = UIImageView()
        imgV.contentMode = .scaleAspectFill
        imgV.clipsToBounds = true
        imgV.layer.masksToBounds = true
        imgV.layer.borderColor = UIColor(hex: 0x000000, alpha: 0.1).cgColor
        imgV.layer.borderWidth = 1
        imgV.layer.cornerRadius = 22
        return imgV
    }()
    
    lazy var nameLabel: UILabel = {
        let lbl: UILabel = UILabel()
        lbl.textColor = UIColor.text.x1d1a1a
        lbl.font = PingFangSCSemiboldFont(16)
        lbl.numberOfLines = 1
        lbl.sizeToFit()
        return lbl
    }()
    
//    lazy var descLabel: UILabel = {
//        let lbl: UILabel = UILabel()
//        lbl.textColor = ListViewSubTitleColor
//        lbl.font = PingFangSCRegularFont(12)
//        lbl.numberOfLines = 1
//        lbl.sizeToFit()
//        return lbl
//    }()
    
    lazy var lineView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor.seprateLine.x707070
        return v
    }()
}
